package com.frxuexi.mdm2205.view

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import com.frxuexi.mdm2205.myview.HBView
import com.frxuexi.mdm2205.myview.MyZanView

lateinit var hbView: HBView
@Composable
fun MessagePage() {

    val lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current

    DisposableEffect(lifecycleOwner) {
        val observer = LifecycleEventObserver { _, event ->
            when (event) {
                Lifecycle.Event.ON_CREATE -> {
                    // Do something when the component is created
                    println("Component Created")
                }
                Lifecycle.Event.ON_START -> {
                    // Do something when the component is started
                    println("Component Started")
                }
                Lifecycle.Event.ON_RESUME -> {
                    // Do something when the component is resumed
                    println("Component Resumed")
                }
                Lifecycle.Event.ON_PAUSE -> {
                    // Do something when the component is paused
                    println("Component Paused")
                }
                Lifecycle.Event.ON_STOP -> {
                    // Do something when the component is stopped
                    println("Component Stopped")
//                    hbView.stop()
                }
                Lifecycle.Event.ON_DESTROY -> {
                    // Do something when the component is destroyed
                    println("Component Destroyed")
                }

                else -> {}
            }
        }

        lifecycleOwner.lifecycle.addObserver(observer)

        onDispose {
            lifecycleOwner.lifecycle.removeObserver(observer)
        }
    }
    AndroidView(modifier = Modifier.fillMaxSize(), factory = {
        /*hbView = HBView(it)
        hbView.start()
        hbView*/
        val myZanView = MyZanView(it)
        myZanView
    })
    

}